package org.ainlolcat.ainscience.column.threshold;

import org.ainlolcat.Variable;
import org.ainlolcat.ainscience.entity.Entity;

/**
 * @author ainlolcat
 *         Date: 5/5/13
 */
public class DeltaThreshold extends AbstractThreshold {

    public DeltaThreshold(int type, double value, boolean filter, boolean local) {
        super(type, value, filter, local);
    }

    public boolean isExceed(Entity entity, int column, int row) {
        Variable before = getValue(entity, column, row - 1);
        Variable current = getValue(entity, column, row);
        Variable next = getValue(entity, column, row + 1);
        double delta = Math.max(
                before!=null ? Math.abs(current.getDoubleValue() - before.getDoubleValue()) : 0,
                next!=null ? Math.abs(current.getDoubleValue() - next.getDoubleValue()) : 0);
        return delta > value;
    }
}
